$(document).ready(function(){
    var type = 'dolike';
    var i = 0;
    console.log('成功插入，坐等出翔......');
    console.log($('script'))
    $('.qz_like_btn_v3').live('click', function(){
        console.log('正在出翔...');
        zanChuXiang(type, this, i)
        // setTimeout(function(){
        //     $.ajax({
        //         type: 'POST',
        //         cache: false,
        //         async: true,
        //         url: url,
        //         data: params.join('&'),
        //         dataType: 'json',
        //         beforeSend: function()
        //         {
        //             console.log(1111111111111)
        //         },
        //         error: function(msg)
        //         {
        //             console.log('fail')
        //             console.log(msg.responseText)
        //         },
        //         success: function(res)
        //         {
        //             console.log('success')
        //             console.log(res);
        //         }
        //     });
        // }, 5000)
    });
    // $('_likeBtn').click(function(){
    //     console.log('正在出翔2...');
    //     zanChuXiang(type, this, i);
    // })
})
function zanChuXiang(type, that, i){
    setTimeout(function(){
        if(i % 2 == 0){
            type = 'dolike';
        }else{
            type = 'unlike';
        }
        httpPost(type, that, i);
        if(i >= 30){
            return 0;
        }
        i ++;
        console.log(i);
        zanChuXiang(type, that, i);
    }, 1000)
}
function httpPost(type, that, fupdate){
    var unikey = $(that).attr('data-unikey');
    var curkey = $(that).attr('data-curkey');
    var spliteCurkey = curkey.split('/');
    var spliteCurkeyTemp = spliteCurkey[spliteCurkey.length - 1].split('.');
    var fid = spliteCurkeyTemp[0];
    var url = 'http://w.cnc.qzone.qq.com/cgi-bin/likes/internal_' + type + '_app?g_tk=459940438';
    var param = {
            qzreferrer:'http://user.qzone.qq.com/469569693/infocenter',
            opuin:469569693,
            unikey: unikey,
            curkey: curkey,
            from: 1,
            appid: 311,
            typeid: 0,
            abstime: 135629,
            fid: fid,
            active: 0,
            fupdate: fupdate,
        };
    var params = [];
    for(var rp in param) {
        params.push(rp +'='+param[rp]);
    }
    console.log(url)
    // var url = url + '&' + params.join('&');
    // console.log(url)
    // var xmlHttp = new XMLHttpRequest(); 
    // xmlHttp.open("POST", url, true);  
    // xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    // xmlHttp.onreadystatechange = function(){
    //     if(xmlHttp.readyState == 4){
    //         console.log(xmlHttp.responseText)
    //     }
    // }
    // xmlHttp.send();
    $.ajax({
        type: 'POST',
        cache: false,
        async: true,
        url: url,
        data: params.join('&'),
        dataType: 'json',
        beforeSend: function()
        {
        },
        error: function(msg)
        {
            console.log(msg.responseText)
        },
        success: function(res)
        {
        }
    });
}